package com.my.blog.website.controller;

import com.wf.captcha.ArithmeticCaptcha;
import com.wf.captcha.GifCaptcha;
import com.wf.captcha.utils.CaptchaUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author ：gyh
 * @date ：Created in 2020/9/9 23:20
 * @description：验证码
 * @modified By：gyh
 * @version: 1.0
 */
@Controller
public class CaptchaController {

    @RequestMapping("/captcha")
    public void captcha(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ArithmeticCaptcha captcha = new ArithmeticCaptcha(130, 48);
        captcha.setLen(2);
        captcha.getArithmeticString();
        captcha.text();
        CaptchaUtil.out(captcha, request, response);
        String verCode = captcha.text().toLowerCase();
        //存入session
        request.getSession().setAttribute("CAPTCHA",verCode);

    }
}
